package net.nutss;

import java.util.ArrayList;
import net.nutss.stunt.STUNTServerSocket;
import net.nutss.stunt.STUNTSocket;
import net.nutss.stunt.STUNTUDPSocket;

public class STUNTSelector {
	public ArrayList aSocket = new ArrayList();
	private Object objLock = new Object();
	public void add(Object o) {
		synchronized (objLock) {
			aSocket.add(o);
		}
	}

	public void remove(Object o) {
		synchronized (objLock) {
			aSocket.remove(o);
		}
	}

	public ArrayList getHasData() {
		ArrayList ba = new ArrayList();
		STUNTSocket so = null;
		STUNTServerSocket ss = null;
		STUNTUDPSocket su = null;
		synchronized (objLock) {
			for (int i = 0; i < aSocket.size(); i++) {
				Object obj = aSocket.get(i);
				if (obj instanceof STUNTSocket) {
					so = (STUNTSocket) obj;
					if (so.hasData())
						ba.add(obj);
				} else if (obj instanceof STUNTServerSocket) {
					ss = (STUNTServerSocket) obj;
					if (ss.hasData())
						ba.add(obj);
				} else if (obj instanceof STUNTUDPSocket) {
					su = (STUNTUDPSocket) obj;
					if (su.hasData())
						ba.add(obj);
				}
			}
		}
		return ba;
	}


}
